package org.zhb.sql.query.core.util;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;

import javax.persistence.Embeddable;
import javax.persistence.MappedSuperclass;

import com.mysema.query.codegen.BeanSerializer;
import com.mysema.query.codegen.GenericExporter;
import com.mysema.query.codegen.Keywords;
import com.mysema.query.sql.codegen.MetaDataExporter;
import com.mysema.query.sql.codegen.NamingStrategy;

public class Export {

	public static NamingStrategy namingStrategy = new CustomeNamingStrategy();

	public static void main(String[] args) throws Exception {
	/*	GenericExporter exporter = new GenericExporter();
		exporter.setKeywords(Keywords.JPA);
		exporter.setEntityAnnotation(Entity.class);
		exporter.setEmbeddableAnnotation(Embeddable.class);
		exporter.setEmbeddedAnnotation(Embedded.class);
		exporter.setSupertypeAnnotation(MappedSuperclass.class);
		exporter.setSkipAnnotation(Transient.class);
		exporter.setTargetFolder(new File("target/generated-sources/java"));
		exporter.export(City.class.getPackage());*/
		// generateCode();
	}

	public static void generateCode() throws Exception {
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost:3306/auth_shiro";
		Connection conn = DriverManager.getConnection(url, "root", "root");

		MetaDataExporter exporter = new MetaDataExporter();
		exporter.setNamingStrategy(namingStrategy);
		exporter.setPackageName("org.zhb.sql.query.model");
		exporter.setBeanSerializer(new BeanSerializer());
		exporter.setTargetFolder(new File("../zhb-sqlquery/src/test/java"));
		exporter.export(conn.getMetaData());

		conn.close();
	}
}
